<?php

namespace app\index\controller\rank;

use app\index\model\UM as UM;
use app\index\service\HotRankIncomeService;
use app\index\service\HotRankSourceService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\Request as Request;

/**
 * 案源消耗榜 控制器
 * Class Source
 * @package app\index\controller\rank;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 * @see \app\index\validate\rank\Income
 */
class Source
{
    // 请求参数
    private Request $request;

    // service
    private HotRankSourceService $service;

    public function __construct(Request $request, HotRankSourceService $service)
    {
        $this->request = $request;
        $this->service = $service;
    }

    /**
     * 案源消耗榜 列表
     * @param UM|null $user
     * @return ApiResponse
     * @url /rank/source/index
     */
    public function index(?UM $user): ApiResponse
    {
        $request = $this->request;

        $timeCondition = $request->param('timeCondition', 'ALL');
        $page = $request->param('page', 1);
        $page_size = $request->param('page_size', 50);

        return ApiResponse::success($this->service->index($user, $timeCondition, $page, $page_size));
    }

}
